<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="z" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
	com.test.model.User currentUser = (com.test.model.User) org.apache.shiro.SecurityUtils.getSubject().getPrincipal();
	request.setAttribute("currentUser", currentUser);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/head.jsp" />
<script type="text/javascript">
  $(function () {
      $("#updateForm").bootstrapValidator({
          message:'This value is not valid',
          feedbackIcons: {
              valid: 'glyphicon glyphicon-ok',
              invalid: 'glyphicon glyphicon-remove',
              validating: 'glyphicon glyphicon-refresh'
          },
          fields:{
              plainOldPassword:{
                  message:'旧密码非法',
                  threshold :3 ,
                  validators:{
                      notEmpty:{
                          message:'旧密码不能为空'
                      },
                      remote: {    
                          url: '/test/validateOldPassword.do',
                          message: '旧密码错误',
                          type: 'POST',
                          data:{     
                              id: function(){ return $("#id").val(); }
                          }
                      },

                  }
              },
              
              plainNewPassword:{
            	  message:'新密码非法',
            	  validators:{
	            	  notEmpty:{
	            	       message:'新密码不能为空'
	            	  },
	            	  stringLength:{
		            	  min:3,
		            	  max:20,
		            	  message:'新密码长度必须位于3到20之间'
	            	  },
	            	  identical:{
		            	  field:'plainNewPassword',
		            	  message:'两次密码输入不一致'
	            	  },
	            	  regexp:{
		            	  regexp:/^[a-zA-Z0-9_\.]+$/,
		            	  message:'新密码由数字字母下划线和.组成'
	            	  },
            	  }
            },
            
            repassword:{
          	  message:'新密码非法',
          	  validators:{
	            	  notEmpty:{
	            	       message:'新密码不能为空'
	            	  },
	            	  stringLength:{
		            	  min:3,
		            	  max:20,
		            	  message:'新密码长度必须位于3到20之间'
	            	  },
	            	  identical:{
		            	  field:'plainNewPassword',
		            	  message:'两次密码输入不一致'
	            	  },
	            	  regexp:{
		            	  regexp:/^[a-zA-Z0-9_\.]+$/,
		            	  message:'新密码由数字字母下划线和.组成'
	            	  },
          	  }
          },
          },
      })     
      })
</script>
<style>
body {
	padding: 40px;
	position: relative;
}

h3 {
	text-align: center;
}
</style>
</head>
<body>
	<nav class="navbar navbar-default navbar-static navbar-fixed-top" role="navigation">
	<div class="container-fluid">
		<div>
			<ul class="nav navbar-nav navbar-right">
				<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">欢迎您，${currentUser.realName}
						<span class="caret"></span>
				</a>
					<ul class="dropdown-menu">
						<shiro:hasPermission name="USER_REGISTER">
							<li><a href="register.jsp" onclick="window.open(this.href);return false"> 注册新用户 </a></li>
						</shiro:hasPermission>
						<li><a href="/test/logout.do">退出登录</a></li>
					</ul></li>
			</ul>
		</div>
	</div>
	</nav>
	<div class="container col-md-8 col-md-offset-2">
		<div class="page-header">
			<h3>更改密码</h3>
		</div>
		<div>
			<form action="/test/updatePassword.do" method="post" id="updateForm" class="form-horizontal">
				<input type="hidden" id="id" name="id" value="${currentUser.id}" />
				<div class="form-group">
					<label for="plainOldPassword" class="col-md-2 control-label">旧密码</label>
					<div class="col-md-7">
						<input type="password" class="form-control" id="plainOldPassword" name="plainOldPassword" placeholder="请输入旧密码">
					</div>
				</div>

				<div class="form-group">
					<label for="plainNewPassword" class="col-md-2 control-label">新密码</label>
					<div class="col-md-7">
						<input type="password" class="form-control" name="plainNewPassword" id="plainNewPassword" placeholder="请输入新密码" />
					</div>
				</div>

				<div class="form-group">
					<label for="repassword" class="col-md-2 control-label">确认新密码</label>
					<div class="col-md-7">
						<input type="password" class="form-control" name="repassword" id="repassword" placeholder="请再次输入新密码" />
					</div>
				</div>

				<div class="form-inline col-md-offset-5">
					<button type="submit" class="btn btn-primary">保存并关闭</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>